package com.example.demo;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;


public class TestDemo {
    
    public static void main(String[] args) {

        List<Map<String, Object>> mapList = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("name", "null");
        map1.put("code", "abc1");
        Map<String, Object> map2 = new HashMap<>();
        map2.put("name", "abc");
        map2.put("code", "abc1");
        Map<String, Object> map3 = new HashMap<>();
        map3.put("name", "abc");
        map3.put("code", "abc1");
        mapList.add(map1);
        mapList.add(map2);
        mapList.add(map3);
        // Stream<Object>是实际转换的,但我想转换成List<T>.
        //Stream<Object> users = mapList.stream().map(x -> x.keySet().stream().map(e -> new TestUser1(x.get("name").toString(), x.get("code").toString())));
        List<TestUser1> users = mapList.stream().map(m -> {
          return   new TestUser1(m.get("name").toString(), m.get("code").toString());
        }).collect(Collectors.toList());
        System.err.println("转换为List" + JSON.toJSONString(users));
    }
}
